
package com.ukao.steward.pesenter.valetRunners;

import com.ukao.steward.base.BasePresenter;
import com.ukao.steward.bean.StringBean;
import com.ukao.steward.bean.WaitingOrderBean;
import com.ukao.steward.consts.Constant;
import com.ukao.steward.consts.SaveParams;
import com.ukao.steward.retrofit.ApiCallback;
import com.ukao.steward.util.L;
import com.ukao.steward.view.valetRunners.TakeLetterView;

import java.util.HashMap;

import rx.Observable;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class TakeLetterPesenter extends BasePresenter<TakeLetterView> {


    public TakeLetterPesenter(TakeLetterView view) {
        attachView(view);
    }

    /**
     取件员  已接单，未取件
     */
    public void  requestReceiving(final   int pageNum ,int pageSize,int  type) {
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("pageNum",pageNum+"");
        mHashMap.put("pageSize",pageSize+"");
        mHashMap.put("accessToken", SaveParams.getToken());
        Observable  observable=null;
        switch (type) {
            case 1:/*未取*/
                observable =apiStores.receiveNoTake(Constant.createParameter(mHashMap));
                break;
            case 2:/*未交*/
                observable =apiStores.received(Constant.createParameter(mHashMap));
                break;
            case 3:/*已交*/
                observable =apiStores.mating(Constant.createParameter(mHashMap));
                break;
        }

        addSubscription(observable,
                new ApiCallback<WaitingOrderBean>() {
                    @Override
                    public void onSuccess(WaitingOrderBean model) {
                        if (model.getHttpCode() == 200) {

                           mvpView.receiveNoTakeSucceed(model.getData());
                        }else{

                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                       mvpView.loadfinish();

                    }
                });

        }








    /**
     设置运单号
     */
    public void addtransNo(final    WaitingOrderBean.ListBean   mListBean,String  transNo) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        L.i("mListBean.getId()="+mListBean.getId());
        mHashMap.put("orderId",mListBean.getId()+"");
        mHashMap.put("transNo",transNo);
        mHashMap.put("accessToken", SaveParams.getToken());
        addSubscription(apiStores.addtransNo(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {
                           mvpView.receivingSucceed(mListBean,model.getMsg());
                        }else{

                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();

                    }
                });

    }
    /**
     计价
     */
    public void modifyPrice(  final    WaitingOrderBean.ListBean   mListBean,final  String  price ) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("orderId",mListBean.getId()+"");
        mHashMap.put("price",price);
        mHashMap.put("accessToken", SaveParams.getToken());
        addSubscription(apiStores.modifyPrice(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {

                            mvpView.modifyPrice(  price,model.getMsg());
                        }else{

                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();

                    }
                });

    }



}
